package com.dl.mall.controller.user;

import com.dl.mall.annotation.MethodInfo;
import com.dl.mall.entity.Page;
import com.dl.mall.entity.Product;
import com.dl.mall.service.user.ProductService;
import com.dl.mall.utils.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 地址类controller
 * @author DL
 * @create 2022-3-23 20:54:30
 */
@Slf4j
@RestController()
@RequestMapping("/brand")
@Api(tags="品牌类controller")
public class BrandController {

    @Resource
    ProductService productService;

    @ApiOperation(value="根据 品牌id 查询改品牌的商品信息",notes = "brandId=品牌id，currentPage=页数")
    @MethodInfo
    @GetMapping(value = {"/{brandId}/{currentPage}"})
    public Result getProductByBrandId(@PathVariable int brandId, @PathVariable int currentPage){
        System.out.println("brandId = " + brandId);
        Page<Product> page = productService.getProductByBrandId(brandId, currentPage, 10);

        System.out.println("page = " + page);
        if (page != null){
            return Result.ok("查询品牌产品成功").data("page", page);
        }else {
            return Result.error("查询品牌产品失败");
        }
    }


}
